package educationaladministrationsystem.CSM.Controller.Root;

import educationaladministrationsystem.Result.Result;
import educationaladministrationsystem.CSM.Mapper.Service.Root.RootCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/Root/Count")
public class RootCountController {
    @Autowired
    private RootCountService rootCountService;

    @GetMapping("/getAllCount")
    public Result getAllCount(@RequestParam int page, @RequestParam int pageNumber) {
        return Result.success(rootCountService.getAllCount(page, pageNumber));
    }

    @GetMapping("/getSearchCount")
    public Result getSearchCount(@RequestParam int page, @RequestParam int pageNumber, @RequestParam String information) {
        return Result.success(rootCountService.getSearchCount(page, pageNumber, information));
    }

    @GetMapping("/getUpdateCountInformation")
    public Result getUpdateCountInformation(@RequestParam String id) {
        return Result.success(rootCountService.getUpdateCountInformation(id));
    }

    @PostMapping("/updateCount")
    public Result updateCount(@RequestBody String countNumber, @RequestParam String newPassword) {
        rootCountService.updateCount(countNumber, newPassword);
        return Result.success();
    }

    @GetMapping("/getPage")
    public Result getPage(@RequestParam int pageNumber) {
        return Result.success(rootCountService.getPage(pageNumber));
    }
}
